﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>加入企业</title>
	<meta charset="utf-8" />
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    <link href="/LiberUI/Style/LiberUI.css" rel="stylesheet" />
    <link href="/SiteUI/Base.css" rel="stylesheet" />
    <link href="/SiteUI/Wechat/WegisteredAccount.css" rel="stylesheet" />
</head>
<body>
    <div id="MainPart">
        <div class="row procedure">
            <img src="/SiteUI/Imgs/Wx-loginSteps3.png" />
        </div>
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2">
                <input id="companyName" type="text" placeholder="请输入企业名称" />
            </div>
            <div class="col-lg-12" id="lstCompanies" style="text-align:left;">
            </div>
        </div>
      </div>

    <div id="tpls">
        <div style="bo">
            <div class="companyView row" style="border-bottom: 1px solid gainsboro;padding:1rem;">
                <h5 class="cv-name">企业名称</h5>
                <div class="col-lg-6">
                    <span class="cv-industry">行业</span>
                    <a class="LinkTo cv-website" target="_blank" href="#">官方网站</a>
                    <br />

                </div>
                <div class="col-lg-2 cv-certify">
                    企业认证
                </div>
                <div class="col-lg-4" style="text-align:center">
                    <a class="btnApply">申请加入</a>
                </div>
            </div>
        </div>
        <div class="col-lg-12" id="pnlCreateCompany" style="margin-top:1rem">
            <span>找不到您所工作的企业？请点这里<a class="LinkTo" id="lnkCreateCompany" target="_self" href="/WxPages/WxCompany.html">创建企业</a></span>
        </div>
        <div id="joinApplyEnd">

        </div>
    </div>
    <script src="/LiberUI/Scripts/jquery.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Base.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Action.js"></script>
    <script src="/SiteUI/res_sobiz.js"></script>
    <script>
        var SetCompany = {
            key: "",
            joinCompanyId: null,
            companies: [],  //所有查询结果
            tpls: document.createDocumentFragment(),
            tplCompanyView: null,
            pnlCreateCompany: null,
            Filtering: false,
            findCompany: function (ev) {
                var k = $("#companyName").vl().trim();//获得文本输入值
                if (!SetCompany.key || k.length > 0 && (k.indexOf(SetCompany.key) != 0 || SetCompany.key.length == 0)) {
                    //仅当新的输入值不是以原先的key为起始，才开始新的查询
                   SetCompany.companies.forEach(function (i) { i.View.remove(); i.View = null; });
                    SetCompany.companies = [];
                    SetCompany.key = k;
                    $.getJSON("/Company/FindCompany", { key: k }, SetCompany.findCompanyEnd);
                }
                else {
                    SetCompany.key = k;
                    SetCompany.filterCompany();
                }
                if (ev) {
                    setTimeout(SetCompany.findCompany, 1000);
                }
            },
            findCompanyEnd: function (rtn) {
                if (rtn.IsPositive) {
                    SetCompany.companies.forEach(function (i) { i.View.remove(); i.View = null; });
                    SetCompany.companies = [];
                    rtn.Data["companies"].forEach(SetCompany.makeCompanyView);
                }
                else {
                    //TODO:查询出现错误的处理
                }
                SetCompany.filterCompany();
            },
            filterCompany: function (refilter) {
                //TODO:针对查询结果执行过滤
             
                for (var n = 0; n < SetCompany.companies.length; n++) {
                    var i = SetCompany.companies[n];
                    console.log(SetCompany.companies)
                    if (i.companyname.indexOf(SetCompany.key) > -1 || i.summy.indexOf(SetCompany.key) > -1) {
                        i.View.appendTo("#lstCompanies").fadeIn();
                    }
                    else {
                        i.View.appendTo(SetCompany.tpls);

                    }
                }
                if (SetCompany.key.length > 0) {
                    SetCompany.pnlCreateCompany.insertAfter("#lstCompanies").fadeIn();
                }
                else {
                    SetCompany.pnlCreateCompany.appendTo(SetCompany.tpls);
                }
            },
            makeCompanyView: function (i) {
                i.View = SetCompany.tplCompanyView.clone();
                i.View.find(".cv-name").vl(i.companyname);
                i.View.find(".cv-connection").vl(i.officephone + "  " + i.address);
                i.View.find(".cv-industry").vl(i.industry);
                i.View.find(".cv-website").attr("href", i.website).vl(i.website);
                i.View.attr("objid", i.idstr);
                if (i.certifyStatus == 'true') {
                    i.View.find(".cv-certify").addClass("positive");
                }
                else {
                    i.View.find(".cv-certify").addClass("negitive");
                }
                SetCompany.companies.push(i);
            },
            joinCompany: function (ev) {
                var c = $(ev.currentTarget);
                var cv = c.parents(".companyView").eq(0);
                SetCompany.joinCompanyId = cv.attr("objid");
                console.log(SetCompany.joinCompanyId);
                if (SetCompany.joinCompanyId) {
                    $.getJSON("/Company/ApplyJoin", { company: SetCompany.joinCompanyId }, SetCompany.joinCompanyEnd);
                }
            },
            joinCompanyEnd: function (rtn) {
                //处理申请发出结果
                if (rtn.IsPositive) {
                    success("您的申请已发送给企业管理人员")
                           .on("disposed", function (ev) { window.location = "/MyBiz/WxIndex?tm=" + new Date().getTime().toString(); });
                }
                else {
                    error("错误：" + ErrFormate(res_sobiz, rtn.ErrorSrc, rtn.ErrorCode, rtn.Error));
                }
            }
        }
        $(function () {
            //获取用户信息
            KeybordHelper.on($("#companyName"), "*", SetCompany.findCompany);
            $("#lstCompanies").delegate(".btnApply", "click", null, SetCompany.joinCompany);
            SetCompany.tplCompanyView = $(".companyView").eq(0).hide();
            SetCompany.pnlCreateCompany = $("#pnlCreateCompany").hide();
           $("#btnFind").on("click", function () {
                SetCompany.key = "";
                SetCompany.findCompany();
            });

            $("#companyName").focus();
        })
    </script>
    <div id="tplPrompt" style="display:none">
        <div class="prompt_success">
            <div class="p_body">
                <span>message</span>
            </div>
        </div>
        <div class="prompt_info">

            <div class="p_body">
                <span>message</span>
            </div>
        </div>
        <div class="prompt_err">
            <div class="p_body">
                <span>message</span>
            </div>
        </div>
    </div>

    <script>
    window.success = function (msg, delay, fnCallback) {
        var cnt = $("#tplPrompt>.prompt_success").clone();
        cnt.children(".p_body").children("span").vl(msg);
        var p = new LiberUI.Prompt(cnt);
        p.option("Delay", delay);
        p.update();
        if (ObjHelper.IsFunc(fnCallback)) {
            p.on("disposed", fnCallback);
        }
        return p.show();

    };
    window.info = function (msg, delay,fnCallback) {
        var cnt = $("#tplPrompt>.prompt_info").clone();
        cnt.children(".p_body").children("span").vl(msg);
        var p = new LiberUI.Prompt(cnt);
        p.option("Delay", delay);
        p.update();
        if (ObjHelper.IsFunc(fnCallback)) {
            p.on("disposed", fnCallback);
        }
        return p.show();
    };
    window.error = function (msg, delay, fnCallback) {
        var cnt = $("#tplPrompt>.prompt_err").clone();
        cnt.children(".p_body").children("span").vl(msg);
        var p = new LiberUI.Prompt(cnt);
        p.option("Delay", delay);
        p.update();
        if (ObjHelper.IsFunc(fnCallback)) {
            p.on("disposed", fnCallback);
        }
        return p.show();
    };

    window.log = function (msg) {
        if (console) {
            console.log(msg);
        }
    };
        </script>
</body>
</html>
